package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.GetUserInfoVO;
import com.luo.model.Result;
import com.luo.model.ResultObj;
import com.luo.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 功能：查询所有用户信息
 * 作者：Luo。
 * 日期：2024/2/15 18:20
 */
@WebServlet("/getUserInfo")
public class GetUserInfoController extends HttpServlet {

    UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<GetUserInfoVO> userInfo = userService.getUserInfo();
        ResultObj resultObj = new ResultObj();
        resultObj.setCode("1");
        resultObj.setMsg("查询成功");
        resultObj.setResult(userInfo);
        String jsonString = JSON.toJSONString(resultObj);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
